/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package koneksi.SQL;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import model.SettingConnection;

/**
 *
 * @author rosi
 */
public class Koneksi {

    private String database = "mstbrg";
    static Connection con;
           
    public  Connection open() {
        try {
            SettingConnection set = new SettingConnection();
            MysqlDataSource ds = new MysqlDataSource();
            ds.setURL(set.bacaUrl());
            ds.setUser(set.bacaUser());
            ds.setPassword(set.bacaPass());
            con = ds.getConnection();
//            JOptionPane.showMessageDialog(null, "Koneksi Berhasil");

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error SQL : "+ex.getMessage());
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(null, "Error File not Found : "+ex.getMessage());
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Error IOException : "+ex.getMessage());
        }
        return con;
    }

    public String getDatabase() {
        System.out.println("use " + database);
        return "use " + database;
    }
}
